<?php

class Sistema_Form_Fullbanner extends Zend_Form
{

    public function init() {
   	    
        $front = Zend_Controller_Front::getInstance();
        $controller = $front->getRequest()->getControllerName();
        $module = $front->getRequest()->getModuleName();
        $url = $front->getBaseUrl().'/'.$module.'/'.$controller;        
        
        $this->setName('form_'.$controller);

        $el = new Zend_Form_Element_Hidden('BAN_ID',array('disableLoadDefaultDecorators' =>true));
        $el->addDecorators(array(array('ViewHelper'),array('Errors')))
            ->addFilter('Int');
        $this->addElement($el);
        
        $obj = new Sistema_Model_DbTable_Catsegmento();
        $row = $obj->fetchAll()->toArray();
        $arr = array();
        foreach($row as $r) $arr[$r['CTS_ID']] = $r['CTS_NOM']; 
        
        $el = new Zend_Form_Element_Select('CTS_ID',array('onchange' => ''));
        $el->setLabel('Segmento')
        ->setRequired(true)
        ->addFilters(array('StripTags','StringTrim'))
        ->addValidator('NotEmpty')
        ->addMultiOptions($arr);
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('BAN_DSC');
        $el->setLabel('Descrição')
                ->setRequired(true)
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');
        $this->addElement($el);
        
        $el = new Zend_Form_Element_Text('BAN_LNK');
        $el->setLabel('Link')
                //->setRequired(true)
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty');
        $this->addElement($el);
                
        
        $el = new Zend_Form_Element_Checkbox('BAN_STA',array('checked'=>'checked'));
        $el->setLabel('Status')
        ->setRequired(true)
        ->addFilter('StripTags')
        ->addFilter('StringTrim')
        ->addValidator('NotEmpty');
        $this->addElement($el);
        
        
        $el = new Zend_Form_Element_Text('BAN_ORD');
        $el->setLabel('Ordem')
                ->setRequired(true)
                ->addValidator('NotEmpty');
        $el->setAttrib('class', 'numero');
        $this->addElement($el);
        
        $img = 'public/upload/'.$controller.'/'.$front->getRequest()->getParam('id').'.*';
        foreach (glob($img) as $src) {
            $el = new Zend_Form_Element('img',array( 'helper'=>'formNote', 'value'=>'<img height="200" src="'.$front->getBaseUrl().'/'.$src.'" />' ));
            $this->addElement($el);
        }
        
        $el = new Zend_Form_Element_File('BAN_FILE');
        $el->setLabel('Imagem')
	->addValidator('Extension', false, array('jpg', 'png', 'gif'));
        $this->addElement($el);
          
        $btn = new Zend_Form_Element_Submit('submit',array('disableLoadDefaultDecorators' =>true));
        $btn->addDecorators(array(array('ViewHelper'),array('Errors')));
        $btn->setAttrib('id', 'submitbutton');
        $btn->setAttrib('class', 'btn-button btn-ok');
        $btn->setLabel('Gravar');
        $this->addElement($btn);
        
        $btn = new Zend_Form_Element_Button('Cancelar',array('disableLoadDefaultDecorators' =>true));
        //$btn->addDecorators(array(array('ViewHelper'),array('Errors')));
        $btn->setDecorators(array(array('Description', array('escape' => false, 'tag' => false))));
        $btn->setDescription('<a href="'.$url.'" class="btn-button btn-cancel">Cancelar</a>');
        $btn->setAttrib('id', 'btncancel');
        $btn->setAttrib('class', 'btn-button btn-cancel');
        $this->addElement($btn);
        
        
    }

}

